Ext.define("ECAT.view.ImgList", {
    extend: 'Ext.Container',
    requires: ['Ext.Img','ECAT.model.Img'], 
    config: {
    	scrollable : 'vertical',
    	store:	null,
    	layout: {
	        type: 'vbox'
    	}
    },
    initialize: function() {
        	this.callParent(arguments);
        	//缩略图异步加载数量为2屏
        	this.renderLimit = ECAT.lib.THUMBNAIL_COLUMN_NUM * ECAT.lib.THUMBNAIL_ROW_NUM * 2;
        	var store = this.config.store;
    		if(store == null){
    			throw 'store is null!';
    		}
    		if(Ext.isString(store)){
				this.store = Ext.getStore(store);    			
    		}else{
	        	this.store = this.config.store;
    		}
        	this.setWidth(ECAT.lib.DWIDTH);
        	this.setHeight(ECAT.lib.DHEIGHT);
			this.renderList();
    },
    renderList : function(records){
    	records = records || this.store.getRange();
    	var	recordsLn = records.length,
    		img_width = ECAT.lib.DWIDTH / ECAT.lib.THUMBNAIL_COLUMN_NUM,
    		img_height = ECAT.lib.DHEIGHT / ECAT.lib.THUMBNAIL_ROW_NUM,
    		hc,i,img_name,renderCount;
    	if(recordsLn > this.renderLimit){
    		renderCount = this.renderLimit;
    	}else{
    		renderCount = recordsLn;
    	}
		for (i = 0; i < renderCount; i++) {
			img_name = records[i].get('name');
			if(i % ECAT.lib.THUMBNAIL_COLUMN_NUM == 0){
				hc = Ext.create('Ext.Container',{
					layout: 'hbox'
				});
				this.add(hc);
			}
			hc.add(Ext.create('Ext.Container',{
				items : [{
					xtype : 'img',
					mode:true,
				    height: img_height,
				    width: img_width,
					src: ECAT.lib.getXiaoImgSrc(img_name),
				    record : records[i]
				}]
			}));
		}
		records.splice(0,renderCount);
		if(!Ext.isEmpty(records)){
			Ext.defer(function(records){
				this.renderList(records);
			},500,this,[records]);
		}
    },
    refreshList : function(){
    	this.removeAll(true,true); 
		this.renderList();
    }
});
